<html>
<head>
    <title>水费记录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../assets/css/dpl-min.css" rel="stylesheet" type="text/css" />
    <link href="../assets/css/bui-min.css" rel="stylesheet" type="text/css" />
    <link href="../assets/css/page-min.css" rel="stylesheet" type="text/css" />   <!-- 下面的样式，仅是为了显示代码，而不应该在项目中使用-->
    <link href="../assets/css/prettify.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        code {
            padding: 0px 4px;
            color: #d14;
            background-color: #f7f7f9;
            border: 1px solid #e1e1e8;
        }
    </style>
</head>
<body>
<form id="searchForm" class="form-horizontal" style="margin: 20px 0px -50px 20px">
    <div class="row">
        <div class="control-group span8">
            <label class="control-label">房号：</label>
            <div class="controls">
                <input type="text" class="control-text" name="roomNum"/>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="control-group span9">
            <label class="control-label">时间选择：</label>
            <div class="controls">
                <input type="text" class=" calendar" name="startTime"/><span> - </span><input name="endTime" type="text" class=" calendar"/>
            </div>
        </div>
        <div class="span3 offset2">
            <button  type="button" id="btnSearch" class="button button-primary">搜索</button>
        </div>
    </div>
</form>
<div class="container">
    <div class="search-grid-container">
        <div id="grid"></div>
    </div>
</div>
<div id="content" class="hide">
    <form id="J_Form" class="form-horizontal">
        <div class="row">
            <div class="control-group span8">
                <label class="control-label"><s>*</s>学校名称：</label>
                <div class="controls">
                    <input name="school" type="text" data-rules="{required:true}" class="input-normal control-text"/>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="../assets/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="../assets/js/bui-min.js"></script>


<script type="text/javascript" src="../assets/js/config-min.js"></script>
<script type="text/javascript" src="../assets/js/config/config.js"></script>
<script type="text/javascript">
    BUI.use('common/page');
</script>
<!-- 仅仅为了显示代码使用，不要在项目中引入使用-->
<script type="text/javascript" src="../assets/js/prettify.js"></script>
<script type="text/javascript">
    $(function () {
        prettyPrint();
    });
</script>
<script type="text/javascript">

    BUI.use(['common/search','bui/overlay'],function (Search,Overlay) {

        var enumObj = {"1":"启用","0":"禁用"},
            columns = [
                {title:'id',dataIndex:'id',width:50},
                {title:'房号',dataIndex:'roomNum',width:100},
                {title:'手机号',dataIndex:'mobile',width:150},
                {title:'水表读数',dataIndex:'multiReadNum',width:200},
                {title:'抄表日期',dataIndex:'submitTime',width:250},
                {title:'操作',dataIndex:'',width:100,renderer : function(value,obj){
                    var editStr =  Search.createLink({ //链接使用 此方式
                            id : 'edit' + obj.id,
                            title : '编辑',
                            text : '编辑',
                            href : '../waterBillEdit.html?id='+obj.id
                        });
                    return editStr;
                }}
            ],
            store = Search.createStore('/backend/waterBills/list'),
            gridCfg = Search.createGridCfg(columns,{
                tbar : {
                    items : [
                    ]
                },
                plugins : [BUI.Grid.Plugins.CheckSelection]
            });

        var  search = new Search({
                store : store,
                gridCfg : gridCfg
            }),
            grid = search.get('grid');

        //新增操作
        function addFunction(){
            location.href = "centerEdit.jsp";
        }

        //编辑操作
        function editFunction(){
            location.href = "centerEdit.jsp";
        }


        //删除操作
        function delFunction(){
            var selections = grid.getSelection();
            delItems(selections);
        }

        function delItems(items){
            var ids = [];
            BUI.each(items,function(item){
                ids.push(item.id);
            });

            if(ids.length){
                BUI.Message.Confirm('确认要删除选中的记录么？',function(){
                    $.ajax({
                        url : 'delUser',
                        dataType : 'json',
                        data : {id : ids[0]},
                        success : function(data){
                            if(data.code === 200){ //删除成功
                                search.load();
                            }else{ //删除失败
                                BUI.Message.Alert('删除失败！');
                            }
                        }
                    });
                },'question');
            }
        }

        //监听事件，删除一条记录
        grid.on('cellclick',function(ev){
            var sender = $(ev.domTarget); //点击的Dom
            if(sender.hasClass('btn-del')){
                var record = ev.record;
                delItems([record]);
            }
        });
    });
</script>

</body>
</html>